package main

import (
	"embed"

	"github.com/wailsapp/wails/v3/pkg/application"
)

func SetSystemTray(app *application.App, iconFS embed.FS) {
	// 前端windows.Hide()函数无效,所以通过事件从后端触发
	app.Event.On("customEvent.windows.Onhide", func(event *application.CustomEvent) {
		app.Hide()
	})
	// Create a new system tray icon
	systray := app.SystemTray.New()
	systray.SetLabel("Slapp3")
	iconBytes, _ := iconFS.ReadFile("frontend/src/assets/logo.png")
	systray.SetIcon(iconBytes)

	menu := application.NewMenu()
	menu.Add("打开主界面").OnClick(func(ctx *application.Context) {
		app.Show()
	})
	menu.Add("隐藏").OnClick(func(ctx *application.Context) {
		app.Hide()
	})
	menu.Add("退出").OnClick(func(ctx *application.Context) {
		app.Quit()
	})

	systray.SetMenu(menu)
}
